﻿
namespace KingerRobot.MexicoSailunMDC.SpiService;

internal class BRcsEquipBuilding : IRcsEquipBuilding
{
    public int GetEquipCrashStatus()
    {
        var db = Db.Default;
        int result;
        result = db.RcsEquipBuildings.Where(t => t.UseFlag == 1).FirstOrDefault()?.CrashStatus ?? (int)EnumCarshStatus.Normal;
        return result;
    }
    public int AddLineMaterialAndTime(long materialId, long equipId)
    {
        var result = 0;
        var db = Db.Default;
        if (equipId == 0)
        {
            return result;
        }
        var building = db.RcsEquipBuildings.Where(t => t.Id == equipId && t.UseFlag == 1);
        if (building is not null)
        {
            var dateTime = DateTime.Now;
            result = db.RcsEquipBuildings.Where(t => t.Id == equipId && t.UseFlag == 1).Update( new PORcsEquipBuilding
            {
                LineMaterialId = materialId,
                LineTime = dateTime,
                UpdateTime = dateTime,
            });
        }
        return db.SaveChanges();
    }
}
